package com.lp.service.impl;

import com.lp.dao.SceneryDao;
import com.lp.po.PagingVO;
import com.lp.po.Scenery;
import com.lp.service.SceneryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SceneryServiceImpl implements SceneryService {
    @Resource
    private SceneryDao sceneryDao;

    @Override
    public int getCount() throws Exception {
        return sceneryDao.count();
    }
    @Override
    public int getCountByName(String sname) throws Exception {
        return sceneryDao.countByName(sname);
    }
    @Override
    public List<Scenery> findAllScenery(Integer toPageNo) {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<Scenery> list=sceneryDao.findSceneryAll(pagingVO);
        return list;
    }
    @Override
    public boolean save(Scenery scenery) {
        Scenery sc = sceneryDao.selectscenerysname(scenery.getSname());
        if (sc == null) {
            sceneryDao.insert(scenery);
            return true;
        }
        return false;
    }
    @Override
    public Scenery findById(Integer id) {
        return sceneryDao.findBySceneryId(id);
    }
    @Override
    public void updataSceneryWhitId(Integer id,String sname,Double latitude,Double longitude,Integer width,
                                    String tximg,String floor,String description,Integer scenerylistid) {
        sceneryDao.updateWhihId(id,sname,latitude,longitude,width,tximg,floor,description,scenerylistid);
    }
    @Override
    public List<Scenery> findBySceneryName(Integer toPageNo,String sname) {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<Scenery> lisst=sceneryDao.findBySceneryName(pagingVO.getTopageNo(),pagingVO.getPageSize(),sname);
        return lisst;
    }
    @Override
    public void delectScenery(Integer id) {
        sceneryDao.removeSceneryById(id);
    }



    /*小程序模块*/
    @Override
    public List<Scenery> wxfindAllScenery(Integer scenerylistid) {
        return sceneryDao.wxfindSceneryAll(scenerylistid);
    }

    @Override
    public List<Scenery> wxfindSceneryByName(String sname) {
        return sceneryDao.wxfindSceneryByName(sname);
    }
}
